<template>
    <div>
        <div id="slider" class="mui-slider">
			<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
				<div class="mui-scroll">
					<!-- 用三元表达式写 mui-active  -->
					<a :class='["mui-control-item",item.id==0?"mui-active":""]' v-for="item in imgcategory" :key="item.id" @click="getPhotolist(item.id)">
						{{item.title}}
					</a>
				</div>
			</div>

		</div>

		<!-- 图片列表区域 -->
		<ul class="photo-ul">
			<router-link v-for="item in imglist" :key="item.id" :to="'/home/photoinfo/'+item.id" tag="li">
				<img v-lazy="randomurl">
				<div class="info">
					<h1 class="info-title">{{item.title}}</h1>
					<div class="info-body">{{item.zhaiyao}}</div>
				</div>	
			</router-link>
		</ul>	
    </div>
	
</template>

<script>
//1.导入mui js
import mui from "../../lib/js/mui.js";
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      imgcategory: [], //所有图片分类
			imglist: [] ,//所有图片
			randomurl:'https://unsplash.it/300/200/?random' //图片失效临时找的随机图片
    };
  },
  created() {
    this.getPhototitle(); //this不能忘记写
    this.getPhotolist(0); //默认进来显示全部 0
  },
  mounted() {
    //2.页面渲染好之后 ,执行初始化滑动控件
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  methods: {
    getPhototitle() {
      //获取图片分类标题
      this.$http.get("api/getimgcategory").then(result => {
        if (result.body.status === 0) {
          // 手动写一个 "全部" 放进去
          result.body.message.unshift({ title: "全部", id: 0 });
          this.imgcategory = result.body.message;
        } else {
          // Toast("图片标题分类,获取失败!")
        }
      });
    },
    getPhotolist(cateid) {
      //获取所有图片
      this.$http.get("api/getimages/" + cateid).then(result => {
        if (result.body.status === 0) {
					// this.imglist.img_url = 'https://unsplash.it/300/200/?random'
          this.imglist = result.body.message;
        } else {
          // Toast("图片获取失败!")
        }
      });
    }
  }
};
</script>

<style lang="sass" scoped>
*{
    touch-action:pan-y;
}
.photo-ul{
	list-style:none;
	margin:0;
	padding:10px;
	padding-bottom:0;
	li{
		postion:relative;
		background-color:#ccc;
		text-algin:center;
		margin-bottom:10px;
		box-shadow:0 0 6px #999;
		img{
			width:100%;
		}
		img[lazy=loading] {
			width: 40px;
			height: 300px;
			margin: auto;
			vertical-align:middle;
			}
	}
.info{
	postion:absolute;
	bottom:0;
	background-color:rgba(0,0,0,0.4);
	color:white;
	text-algin:left;
	max-height:84px;
	overflow: hidden;
	.info-title{
		font-size:14px;
	}
	.info-body{
		font-size:12px;
	}
}
}
</style>
